package com.wingsofts.myapplication

import android.os.Bundle
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import android.widget.TextView
import androidx.appcompat.app.AppCompatActivity
import androidx.recyclerview.widget.LinearLayoutManager
import androidx.recyclerview.widget.RecyclerView
import androidx.recyclerview.widget.RecyclerView.ViewHolder
import com.wingsofts.myapplication.ThreeDLayout
import com.wingsofts.myapplication.WeatherActivity.Adapter.MyViewHolder
import java.util.*

class WeatherActivity : AppCompatActivity() {
    var recyclerView: RecyclerView? = null
    private var adapter: Adapter? = null
    private var flag = true
    var list: MutableList<String> = ArrayList()
    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        setContentView(R.layout.activity_weather)
        recyclerView = findViewById<View>(R.id.recyclerView) as RecyclerView
        list.add("周日")
        list.add("周一")
        list.add("周二")
        list.add("周三")
        list.add("周四")
        list.add("周五")
        list.add("周六")
        adapter = Adapter(list)
        recyclerView!!.adapter = adapter
        recyclerView!!.layoutManager = LinearLayoutManager(this)
        val layout = findViewById<View>(R.id.td_header) as ThreeDLayout
        layout.setTouchable(true)
        layout.setTouchMode(ThreeDLayout.Companion.MODE_BOTH_X_Y)
    }

    fun onClick(v: View?) {
        val layout = findViewById<ThreeDLayout>(R.id.td_header)
        if (!flag) {
            flag = true
            (findViewById<View>(R.id.textView) as TextView).text = "72℉"
        } else {
            flag = false
            (findViewById<View>(R.id.textView) as TextView).text = "30℃"
        }
        layout.startHorizontalAnimate(1000)
        for (i in list.indices) {
            (recyclerView!!.getChildAt(i) as ThreeDLayout).startHorizontalAnimateDelayed(
                100 * i.toLong(),
                1000
            )
        }
    }

    internal inner class Adapter(var list: List<String>) :
        RecyclerView.Adapter<MyViewHolder>() {
        override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): MyViewHolder {
            return MyViewHolder(
                LayoutInflater.from(parent.context).inflate(R.layout.item_main, parent, false)
            )
        }

        override fun onBindViewHolder(holder: MyViewHolder, position: Int) {
            holder.textView.text = list[position]
        }

        override fun getItemCount(): Int {
            return list.size
        }

        internal inner class MyViewHolder(itemView: View) :
            ViewHolder(itemView) {
            var textView = itemView.findViewById<View>(R.id.textView) as TextView
            var temperatureTxt = itemView.findViewById<View>(R.id.tv_temperature) as TextView

        }

    }
}